<?php
include_once 'admin-functions.php'; 
include_once '../functions.php'; 
// start our session
session_start();

// load page
if (isset($_GET['p']) && isset($_SESSION['logged_in'])){
	// the p variable is the page name
	$page = $_GET['p'];
	// add the php extension to our page name
	$page .= ".php";
}

// logout
if (isset($page) && $page == "logout.php") {
	session_unset();
	session_destroy();
	$_SESSION = array();
	header('Location: login.php');
}

// or load the page
elseif (isset($_SESSION['logged_in']) && isset($page)) {
	include_once 'theme/top.php';
	include $page;
	include_once 'theme/bottom.php';
}

// if you're not logged in then you shouldn't be here!
else {
	$error = "Whoops! Denied! Login?";
	include 'login.php';
}

?>